#
# @lc app=leetcode.cn id=69 lang=python3
#
# [69] x 的平方根
#

# @lc code=start
class Solution:
    def mySqrt(self, x: int) -> int:
        if x <= 1:
            return x 
        
        min = 1
        max = x
        result = min 
        while min <= max:
            mid = (min + max)//2
            
            if mid * mid > x:
                max = mid - 1
            elif mid * mid < x:
                result = mid 
                min = mid + 1
            else:
                return mid 
            
        return result
    
# Solution().mySqrt(8)
# @lc code=end

